﻿// 项目：	Guan.CMS.Domain - Guan.CMS
// 文件名：	RemoveProductCategory.cs
// 
// 修改时间：2013-03-16 2:07
// 修改人：	Cooclsee

using Guan.CMS.CommandProcessor.Command;
using Guan.CMS.CommandProcessor.Dispatcher;
using Guan.CMS.Data.Infrastructure;
using Guan.CMS.Data.Repositories;
using Guan.CMS.Domain.Commands.ProductCategory;

namespace Guan.CMS.Domain.Handlers.ProductCategory
{
    public class RemoveProductCategoryHandler : ICommandHandler<RemoveProductCategoryCommand>
    {
        private readonly IProductCategoryRepository _productCategoryRepository;
        private readonly IUnitOfWork _unitOfWork;

        public RemoveProductCategoryHandler(IProductCategoryRepository productCategoryRepository, IUnitOfWork unitOfWork)
        {
            this._productCategoryRepository = productCategoryRepository;
            this._unitOfWork = unitOfWork;
        }

        public ICommandResult Execute(RemoveProductCategoryCommand command)
        {
            var category = _productCategoryRepository.GetById(command.Id);
            _productCategoryRepository.Delete(category);
            _unitOfWork.Commit();
            return new CommandResult(true);
        }
    }
}